//
//  RHMePriceCityCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2025/1/22.
//

#import "RHMePriceCityCell.h"
#import "RHMeElectricPricePatternModel.h"
@interface RHMePriceCityCell()
@property (nonatomic, strong) UIImageView *arrowImg;

@property (nonatomic, strong) QMUITextField *textField;

@property (nonatomic, strong) QMUILabel *titleLab;
@end
@implementation RHMePriceCityCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

-(void)setModel:(RHMeElectricPricePatternModel *)model
{
    _model = model;
    _textField.text = model.content;
    _textField.placeholder = model.placeHolder;
    _titleLab.text = [NSString stringWithFormat:@"*%@",model.title.rh_localized];
    _titleLab.attributedText = [NSString attributeStringWithContent:_titleLab.text attriFont:kSYSTEMFONT(12) attriColor:kCOLOR_HEX(@"#F95454") attriKey:@"*"];
}

- (void)setupUI{
    kWeakSelf;
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    UIView *bgView = [[UIView alloc]init];
    [self.contentView addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView rounded:8 width:1 color:kBorderColor];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
        make.height.offset(44);
    }];
    
    

    _titleLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    _titleLab.numberOfLines = 2;
    [bgView addSubview:_titleLab];
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.centerY.mas_offset(0);
        make.width.offset(80);
    }];
    
    _arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_2"]];
    [bgView addSubview:_arrowImg];
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(18);
        make.right.mas_offset(-5);
        make.centerY.mas_offset(0);
    }];
    _arrowImg.hidden = YES;

    _textField = [[QMUITextField alloc]init];
    _textField.font = kSYSTEMFONT(14);
    _textField.textColor = kCOLOR_HEX(@"#303133");
    _textField.textAlignment = NSTextAlignmentRight;
    _textField.userInteractionEnabled = NO;
    [bgView addSubview:_textField];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.height.offset(35);
        make.centerY.mas_offset(0);
        make.left.equalTo(weakSelf.titleLab.mas_right).offset(5);
    }];
    
    [_textField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        weakSelf.model.content = x;
    }];
}

@end
